package com.own.business.push.core.model;

import com.alibaba.fastjson2.JSON;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * MessagePushContentModel
 * <p>
 * 推送的消息内容
 *
 * @author chenxueli
 * @date 2023-10-20 11:27:00
 */
@Data
@Accessors(chain = true)
public class MessagePushContentModel implements Serializable {

    /**
     * 通知标题
     */
    private String notificationTitle;

    /**
     * 消息标题
     */
    private String title;

    /**
     * 消息内容
     */
    private String content;

    /**
     * 扩展属性
     */
    private Map<String, String> extras;

    /**
     * 添加扩展属性
     *
     * @param key   键
     * @param value 值
     */
    public void addExtras(String key, String value) {
        if (extras == null) {
            extras = new HashMap<>(5);
        }
        int max = 10;
        if (extras.size() >= max) {
            throw new RuntimeException("扩展属性字段数量超出限制");
        }
        extras.put(key, value);
    }

    /**
     * 扩展属性转json字符串
     *
     * @return json字符串
     */
    public String extrasToJsonString() {
        if (extras != null) {
            return JSON.toJSONString(extras);
        }
        return "";
    }

}
